from enum import Enum

import uvicorn
from fastapi import FastAPI
from fastapi.openapi.docs import get_swagger_ui_html
from starlette.staticfiles import StaticFiles

# 创建 FastAPI 应用实例，并把默认的/docs请求禁用
# debug表示是否开启调试模式，默认是False
app = FastAPI(docs_url=None,debug=True)
app.mount("/static", StaticFiles(directory="static"), name="static")    # 静态文件

@app.get("/docs", include_in_schema=False)
def custom_swagger_ui():
    return get_swagger_ui_html(
        openapi_url = "/openapi.json",
        title = "Swagger UI for FastAPI",
        swagger_js_url="/static/swagger-ui-bundle.min.js",
        swagger_css_url="/static/swagger-ui.min.css"
    )
@app.get("/users/current")
async def get_current_user():
    return {"username": "Fake user"}

# 跳径参数
# 在路由函数中指定类型是int，那么它就要求输入的内容必须要可以转为数字
@app.get("/users/{user_id}")
async def get_user(user_id: int):
    return {"user_id": user_id}

# 枚举参数,Gender继承了str类型和Enum类型
class Gender(str, Enum):
    MALE = "male"
    FEMALE = "female"

@app.get("/students/{gender}")
async def get_user(gender: Gender):
    return {"student gender" : gender.value}


if __name__ == '__main__':
    uvicorn.run("main:app", host="127.0.0.1", port=8001, reload=True)